package me.jessyan.mvparms.demo.mvp.ui.activity.store;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.store.DaggerStoreComponent;
import me.jessyan.mvparms.demo.di.module.store.StoreModule;
import me.jessyan.mvparms.demo.mvp.contract.store.StoreContract;
import me.jessyan.mvparms.demo.mvp.presenter.store.StorePresenter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.StoreVpAdapter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;
import me.jessyan.mvparms.demo.mvp.ui.widget.SlideTabView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 店铺
 */
public class StoreActivity extends BaseActivity<StorePresenter> implements StoreContract.View {

    @BindView(R.id.toolbar)
    CustomToolbar toolbar;
    @BindView(R.id.store_iv)
    ImageView storeIv;
    @BindView(R.id.store_name_tv)
    TextView storeNameTv;
    @BindView(R.id.notice_tv)
    TextView noticeTv;
    @BindView(R.id.sub_tv)
    TextView subTv;
    @BindView(R.id.tab)
    SlideTabView tab;
    @BindView(R.id.viewpager)
    ViewPager viewpager;

    private List<String> tabStrs;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerStoreComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .storeModule(new StoreModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_store; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
        initViewpager();
    }

    private void initViewpager() {
        tabStrs = new ArrayList<>();
        tabStrs.add("商家");
        tabStrs.add("领券");


        StoreVpAdapter adapter = new StoreVpAdapter( tabStrs, getApplicationContext());
        viewpager.setOffscreenPageLimit(1);
        viewpager.setAdapter(adapter);
        tab.initTab(tabStrs, viewpager);

        adapter.setListener(new StoreVpAdapter.VpAdapterListener<Boolean>() {
            @Override
            public void getItem(View view, int type, Boolean data) {

            }
        });
    }
    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


}
